-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slightly clean up externalizeUTWithJson #1531
Conversation
Download the artifacts for this pull request here: GUI:
CLI: |
UndertaleModTool/Scripts/Community Scripts/UndertaleWithJSONs.csx
Outdated
Show resolved
Hide resolved
if (Data.GeneralInfo.Major < 2) // Undertale PC (GMS1) | ||
{ | ||
ImportGMLString("gml_Script_textdata_en", @" | ||
if (variable_global_exists(""text_data_en"")) | ||
ds_map_destroy(global.text_data_en); | ||
global.text_data_en = scr_84_load_map_json(program_directory + ""\lang\"" + ""lang_en.json"");"); | ||
ImportGMLString("gml_Script_textdata_ja", @" | ||
if (variable_global_exists(""text_data_ja"")) | ||
ds_map_destroy(global.text_data_ja); | ||
global.text_data_ja = scr_84_load_map_json(program_directory + ""\lang\"" + ""lang_ja.json"");"); | ||
} | ||
else | ||
{ | ||
ImportGMLString("gml_Script_textdata_en", @" | ||
if (variable_global_exists(""text_data_en"")) | ||
ds_map_destroy(global.text_data_en); | ||
global.text_data_en = scr_84_load_map_json(program_directory + ""\lang\\"" + ""lang_en.json"");"); | ||
ImportGMLString("gml_Script_textdata_ja", @" | ||
if (variable_global_exists(""text_data_ja"")) | ||
ds_map_destroy(global.text_data_ja); | ||
global.text_data_ja = scr_84_load_map_json(program_directory + ""\lang\\"" + ""lang_ja.json"");"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked if ""\lang\\""
can be ""\lang\""
for GMS 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldnt matter.
it essentially wants to do program directory + \lang\ + lang_ja.json
(or lang_en). Hence why I replaced it with a slash, as that then also works for all operating systems properly instead of just Windows. and these two paths program_directory/lang
or program_directory/////lang
are the same.
UndertaleModTool/Scripts/Community Scripts/UndertaleWithJSONs.csx
Outdated
Show resolved
Hide resolved
if (Data.GeneralInfo.Major < 2) // Undertale PC (GMS1) | ||
// Undertale PC (GMS1) | ||
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json")); | ||
|
||
string pattern = ".*ds_map_create\\(\\)"; | ||
string replacement = "{"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
// Undertale Switch/Probs other consoles (GMS2) | ||
if (Data.GeneralInfo.Major >= 2) | ||
{ | ||
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json")); | ||
|
||
string pattern = ".*ds_map_create\\(\\)"; | ||
string replacement = "{"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
pattern = @"\\"; | ||
replacement = @"\\"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
pattern = @""" \+ '""' \+ """; | ||
replacement = @"\"""; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
|
||
pattern = @"'""' \+ """; | ||
replacement = @"""\"""; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
|
||
pattern = @""" \+ '""'"; | ||
replacement = @"\"""""; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
|
||
pattern = @"'""'"; | ||
replacement = @"\"""; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
|
||
input = input.Replace(@"\"",", @"\"""","); | ||
|
||
pattern = @"ds_map_add\(global\.text_data_.., ("".*""), ("".*"")\)"; | ||
replacement = @" $1: $2,"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
pattern = @",\n\Z"; | ||
replacement = "\n}"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), input); | ||
|
||
IncProgressLocal(); | ||
UpdateProgressValue(GetProgress()); | ||
} | ||
else // Undertale Switch/Probs other consoles (GMS2) | ||
{ | ||
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json")); | ||
|
||
string pattern = ".*ds_map_create\\(\\)"; | ||
string replacement = "{"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
pattern = @"ds_map_add\(global\.text_data_.., ("".*""), ("".*"")\)"; | ||
replacement = @" $1: $2,"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
pattern = @",\n\Z"; | ||
replacement = "\n}"; | ||
input = Regex.Replace(input, pattern, replacement); | ||
|
||
File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same question here as for lines 69-90
Co-authored-by: Vladislav Stepanov <[email protected]>
UndertaleModTool/Scripts/Community Scripts/UndertaleWithJSONs.csx
Outdated
Show resolved
Hide resolved
This should probably be redone when the Underanalyzer decompiler is merged in. In its current state, this script produces invalid JSON, due to the regex hacks of parsing the decompiler's output string (so we should hold off on merging). With Underanalyzer, the AST can be directly returned from the decompiler, skipping the step of printing to a string, and allowing a simple iteration over the raw string contents in the tree. |
Description
See title
Caveats
I did not test this at all